//@author A0101878B
#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace StorageTest
{		
	TEST_CLASS(UnitTest1)
	{
	public:
		/*
		TEST_METHOD(BasicTest)
		{
			// TODO: Your test code here

				Storage s1;
				Task a1 ("78","1","1","1");
				vector<Task> b1;
				s1.loadFile();
				s1.add(a1,b1);
				s1.remove ("2");
				s1.mark("Task Completed","3");
				s1.reschedule ("3","just kidding","haha");
				s1.rename("nooo", "2");
				s1.remove ("nooo");
				cout << s1.search("45",b1) << endl;
				cout << b1.size() << endl;
				s1.displayAll(b1);
				Task r1 ("57","1","1","1");
			//	s1.add(r1,b1);
				vector<string> sub1; 
				vector<string> sub2;
				string testStr = "78";
				vector<string> string1; 
				string1.push_back("din");
				int a = SUCCESS_ADD;
				Assert::AreEqual ( s1.add(a1,sub1), a);
				Assert::AreEqual (sub1[0],testStr);
				a = SUCCESS_SEARCH;
				Assert::AreEqual (s1.searchTaskName("78",b1),a);
			//	a = SUCCESS_UPDATE;
			//	Assert::AreEqual (s1.rename("dinne asldlsanlan","71222"),a);
			//	s1.rename("4","nooo");
				a = SUCCESS_MARK;
				Assert::AreEqual (s1.mark("78"),a);
				a = SUCCESS_REMOVE;
				Assert::AreEqual (a,s1.remove("78",sub1));


				s1.displayStatus(true,b1);
			   // s1.displayAll(b1);
				a=b1.size();
				Assert::AreEqual(a,2);
				a = SUCCESS_SEARCH;
				Assert::AreEqual(s1.searchKeywords(string1,b1),a);
				a=b1.size();
				Assert::AreEqual (a,4);

				s1.saveFile();
		}*/
		TEST_METHOD (LOad_and_SAve){
			Storage storage_sub; 
		}
		TEST_METHOD (Tests_for_search){
		  Storage storage_sub; 
		}

		TEST_METHOD (Add_Task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
//			storage_sub.loadFile();
			Task to_be_added ("ST3131 tutorial and lecture review","", "Thu Apr 10 23 59 59 2014","NUS");

			int a = SUCCESS_ADD;
			Assert::AreEqual ( storage_sub.add(to_be_added,string_sub1), a);
//			storage_sub.saveFile();
	}
		TEST_METHOD (Rename_of_task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

			Task to_be_added ("study with Quang","Wed:1/2/3/3:2:3", "Thur/1/2/3/4:5:1","NUS");

			storage_sub.add(to_be_added,string_sub1);
			int a = SUCCESS_RENAME;
			Assert::AreEqual( storage_sub.rename("study with Benhi","study with Quang",string_sub1,string_sub2),a);
		}
		TEST_METHOD (Rename_floating_task){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

		//	Task to_be_added ("study with Quang","", "T","NUS");

		//	storage_sub.add(to_be_added,string_sub1);
			storage_sub.loadFile();
			int a = WARNING_RENAME_CLASH;
			Assert::AreEqual( storage_sub.rename("study with Quang","now, study with me",string_sub1,string_sub2),a);
			
		}
		TEST_METHOD (Rename_error_cant_find){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

			storage_sub.loadFile();
			int a = ERROR_RENAME;
			Assert::AreEqual( storage_sub.rename("now, study ","Dinner with me",string_sub1,string_sub2),a);
			storage_sub.saveFile();
		}
		TEST_METHOD (Rename_error_clash){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

			storage_sub.loadFile();
			int a = WARNING_RENAME_CLASH;
			Assert::AreEqual( storage_sub.rename("ST3131 tutorial and lecture review","now, study ",string_sub1,string_sub2),a);
			storage_sub.saveFile();
		}
		TEST_METHOD (Reschedule_of_task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			storage_sub.loadFile();
//			Task to_be_added ("study with Quang","Wed:1/2/3/3:2:3", "Thur/1/2/3/4:5:1","NUS");

//			storage_sub.add(to_be_added,string_sub1);
			int a = SUCCESS_RESCHEDULE;
			Assert::AreEqual( storage_sub.reschedule ("cs2103 v0.2 review with quang", "Sat Apr 12 22 00 00 2014","Sat Apr 12 23 59 59 2014", string_sub1,string_sub2),a);
			storage_sub.saveFile();
		}

		TEST_METHOD (Remove_of_task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

			Task to_be_added ("CS2103 meeting,this is boring!!","Wed/1/2/3:3:2:3", "Thur/1/2:3/4:5:1","NUS");
			storage_sub.add(to_be_added,string_sub1);
			int a = SUCCESS_REMOVE;
			Assert::AreEqual ( storage_sub.remove ("CS2103 meeting,this is boring!!",string_sub1),a);
		}
		TEST_METHOD (Search_exact_taskName){
			Storage storage_sub; 
			vector <string> string_sub1;
			vector<string> string_sub2; 
			vector <Task> Task_sub;

			storage_sub.loadFile();
			int a = SUCCESS_SEARCH;
			Assert::AreEqual(storage_sub.searchTaskName ("IE2100 tutorial practice",string_sub1),a);
		}
		
		TEST_METHOD (KeyWord_match){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2; 
			string keyword;
			vector <Task> task_sub;
			keyword = "din";
			storage_sub.loadFile();
			int a = SUCCESS_SEARCH;
			Assert::AreEqual (storage_sub.searchKeywords(keyword,task_sub),a);
			unsigned int expected_size = 10;
			Assert::AreEqual (task_sub.size(),expected_size);

			keyword = "ie tut";
			expected_size = 10;
			Assert::AreEqual(storage_sub.searchKeywords(keyword,task_sub),a);
			Assert::AreEqual(task_sub.size(),expected_size);
		}
		
		TEST_METHOD (Relocate_of_task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;

	

		//	Task to_be_added ("study with Quang","Wed:1/2/3/3:2:3", "Thur/1/2/3/4:5:1","NUS");
		//	storage_sub.add(to_be_added,string_sub1);
			storage_sub.loadFile();
			int a = SUCCESS_RELOCATE;
			Assert::AreEqual( storage_sub.relocate("study with Quang","NUS utown",string_sub1,string_sub2),a);
			storage_sub.saveFile();
		}

		TEST_METHOD (Display_all_task) {
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			vector<Task> task_sub;

			storage_sub.loadFile();
			unsigned int a=10; 
			storage_sub.displayAll(task_sub);
			Assert::AreEqual (task_sub.size(),a);	
			storage_sub.saveFile();
		}
		TEST_METHOD (Mark_task){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			vector<Task> task_sub;

			storage_sub.loadFile();
			int a = SUCCESS_MARK;
			Assert::AreEqual (storage_sub.mark("IE2150 tutorial practice"),a);
			storage_sub.saveFile();
		}
		TEST_METHOD (Unmark_task){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			vector<Task> task_sub;

			storage_sub.loadFile();
		//	storage_sub.mark("dinner with Ayush");
			int a = SUCCESS_UNMARK;
			Assert::AreEqual (storage_sub.unmark("study with quang"),a);
			storage_sub.saveFile();
		}
		TEST_METHOD (Test_today_add){
		    Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			vector<Task> task_sub;

		

			time_t time1=time(NULL);
	        struct tm time2;
			localtime_s(&time2, &time1);
			int day, month, year;
			day = time2.tm_mday;
			month = time2.tm_mon + 1;
			year = time2.tm_year + 1900;
			
			DateTime start = DateTime(year, month, day);
			DateTime end = DateTime(year, month, day, 23, 59, 59);

			Task to_be_added ("Today Task",start.getDateTimeString(),end.getDateTimeString(), "NUS");

			storage_sub.loadFile();
			storage_sub.add(to_be_added,string_sub1);
			storage_sub.saveFile();
		}
		TEST_METHOD (Display_today){
			Storage storage_sub; 
			vector<string> string_sub1; 
			vector<string> string_sub2;
			vector<Task> task_sub;

			storage_sub.loadFile();
			unsigned int a= 1; 
			storage_sub.displayToday(task_sub);
			Assert::AreEqual (task_sub.size(),a);
	//		string compare = "10/04/2014/ 10:00:00";
	//		Assert::AreEqual(compare,task_sub[0].getEndTime());
		}

		TEST_METHOD (Search_empty_slots){
			Storage storage_sub;
			vector <string> string_sub;

			storage_sub.loadFile();
			storage_sub.searchEmptySlots ("Thu Apr 10 00 00 00 2014","Thu Apr 10 23 59 59 2014",string_sub);
			unsigned int a = 0;
			Assert::AreEqual (string_sub.size(), a);
			string compare  = "10/04/2014/ 13:00:00";
		//	Assert::AreEqual (compare,string_sub[1]);
		}
		
		
		TEST_METHOD (Is_Existing){
			Storage storage_sub;
			storage_sub.loadFile();
			Task  task1 = Task ("ST3131 tutorial and lecture review","","","");
			Task task2 = Task ("St2131 tutorial","","","");
			
			Assert ::AreEqual (storage_sub.isExisting(task1),true);
			Assert::AreEqual(storage_sub.isExisting(task2),false);

		}
		TEST_METHOD (vector_string_test){
			Storage storage_sub;
			string s1 = "abcd";
			vector <string> v1;
			v1 = storage_sub.breakStringintoCombi(s1);
			unsigned int it = 10;
			Assert::AreEqual(v1.size(),it);
			string s2 ="abcd";
	//		string s3 = "ab";
	//		string s4 = "bc";
			Assert::AreEqual(v1[0],s2);
	//		Assert::AreEqual(v1[1],s3);
	//		Assert::AreEqual(v1[2],s4);

		}
		TEST_METHOD (Search_sub_string){
			Storage storage_sub;
			vector<Task> task_sub;
			storage_sub.loadFile();
			storage_sub.searchKeywords("ie2110", task_sub);
			unsigned int a =5;
			Assert::AreEqual(task_sub.size(),a);
			string task1 = "1111";
			Assert::AreEqual(task_sub[1].getTaskName(),task1);

		}
	};
}